package common05.common;

import lombok.Data;

@Data
public class Results<T> {

    private int code;
    private String msg;
    private T data;

    private Results() {
    }

    private Results(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private Results(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }


    private static final int SUCCESS_CODE = 200;
    private static final String SUCCESS_MSG = "SUCCESS";

    public static Results success() {
        return new Results(SUCCESS_CODE, SUCCESS_MSG);
    }

    public static Results success(Object data) {
        return new Results(SUCCESS_CODE, SUCCESS_MSG, data);
    }


    private static final int ERROR_CODE = 500;
    private static final String ERROR_MSG = "UNKNOWN_ERROR";

    public static Results error() {
        return new Results(ERROR_CODE, ERROR_MSG);
    }

    public static Results error(String msg) {
        return new Results(ERROR_CODE, msg);
    }


    private static final int UNAUTHORIZED_CODE = 401;
    private static final String UNAUTHORIZED_MSG = "UNAUTHORIZED";

    public static Results unauthorized() {
        return new Results(UNAUTHORIZED_CODE, UNAUTHORIZED_MSG);
    }


    private static final int FORBIDDEN_CODE = 403;
    private static final String FORBIDDEN_MSG = "FORBIDDEN";

    public static Results forbidden() {
        return new Results(FORBIDDEN_CODE, FORBIDDEN_MSG);
    }


    private static final int NOT_FOUND_CODE = 404;
    private static final String NOT_FOUND_MSG = "NOT_FOUND";

    public static Results not_found() {
        return new Results(NOT_FOUND_CODE, NOT_FOUND_MSG);
    }


    private static final int METHOD_NOT_ALLOWED_CODE = 405;
    private static final String METHOD_NOT_ALLOWED_MSG = "METHOD_NOT_ALLOWED";

    public static Results method_not_allowed() {
        return new Results(METHOD_NOT_ALLOWED_CODE, METHOD_NOT_ALLOWED_MSG);
    }


    private static final int UNSUPPORTED_MEDIA_TYPE_CODE = 415;
    private static final String UNSUPPORTED_MEDIA_TYPE_MSG = "UNSUPPORTED_MEDIA_TYPE";

    public static Results unsupported_media_type() {
        return new Results(UNSUPPORTED_MEDIA_TYPE_CODE, UNSUPPORTED_MEDIA_TYPE_MSG);
    }


    private static final int SERVICE_UNAVAILABLE_CODE = 503;
    private static final String SERVICE_UNAVAILABLE_MSG = "SERVICE_UNAVAILABLE";

    public static Results service_unavailable() {
        return new Results(SERVICE_UNAVAILABLE_CODE, SERVICE_UNAVAILABLE_MSG);
    }






    /*以下是自定义业务返回码================================================================*/

    private static final int PARAM_ERROR_CODE = 11000;
    private static final String PARAM_ERROR_MSG = "PARAM_ERROR";

    public static Results param_error() {
        return new Results(PARAM_ERROR_CODE, PARAM_ERROR_MSG);
    }

    public static Results param_error(String msg) {
        return new Results(PARAM_ERROR_CODE, msg);
    }


}
